import java.util.Scanner;

public class Two {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int ret=0,prevMin= in.nextInt();
        int x=0;
        for (int i = 1; i < n; i++) {
            x=in.nextInt();
            ret=Math.max(ret,x-prevMin);
            prevMin=Math.min(prevMin,x);
        }
        System.out.println(ret<0?0:ret);
    }
}
